var OPENID;

$(document).ready(function(){

    document.getElementById('userid').focus();

    // alert(' 引用成功！ ');
    /*回车事件*/
    $('#userid').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            //需要处理的事情
            getusername();
            // document.getElementById('pass').focus();

        }
    });
    $('#pass').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            //需要处理的事情
            login();
        }
    });

});

function login(){
    var userid=$('#userid').val().toString();
    var pass=$('#pass').val().toString();

    var str={"username":userid,"password":pass};

    console.log(str);

    $.ajax({
        url : strLin + "dynamicQuery/querySqlString/select userid,username,password,open_id from sys_user where userid=" +userid,
        type : "GET",
        dataType: 'json',
        contentType: "application/json;charset=UTF-8",
        success : function(cdata) {
            let data=cdata.data;
            if (pass==data[0].password){
                // location.replace("whiteMain.html?username="+ $('#username').val().toString() +"&openid=" + OPENID);
                // location.replace("whiteMain.html?username="+ $('#username').val().toString());
                location.replace("whiteMain.html?username="+ data[0].username);

            }else{
                $("#username").val('账号或密码错误，请重新录入！');
                $("#pass").val('');
                // document.getElementById('username').focus();


            }
        },
        //请求失败，包含具体的错误信息
        error : function(e){
            $("#pass").val('');
        }
    })
}

// 根据工号获取对应的用户名称
function getusername() {
    var userid=$('#userid').val().toString();
    console.log(strLin + "dynamicQuery/querySqlString/select userid,username,password,open_id from sys_user where userid=" +userid)
    $.ajax({
        url : strLin + "dynamicQuery/querySqlString/select userid,username,password,open_id from sys_user where userid=" +userid,
        type : "GET",
        dataType: 'json',
        contentType: "application/json;charset=UTF-8",
        success : function(cdata) {
           let data=cdata.data;
           if (data.length>0){
            $("#username").val('');
            $("#username").val(data[0].username);
            document.getElementById('pass').focus();
           }else{
               $("#username").val('无此用户，请重新录入！');
               $("#userid").val('');
               // document.getElementById('username').focus();
           }
        },
        //请求失败，包含具体的错误信息
        error : function(e){
            $("#username").val('');

        }
    })
}
